//angular.module('starter.controllers', [])
//
//.controller('DashCtrl', function($scope) {
//  $scope.onTabSelected = function(){
//    alert(1);
//  }
//})
//
//.controller('ChatsCtrl', function($scope, Chats) {
//  // With the new view caching in Ionic, Controllers are only called
//  // when they are recreated or on app start, instead of every page change.
//  // To listen for when this page is active (for example, to refresh data),
//  // listen for the $ionicView.enter event:
//  //
//  //$scope.$on('$ionicView.enter', function(e) {
//  //});
//    $scope.onTabSelected = function(){
//        alert(1);
//    }
//  $scope.chats = Chats.all();
//  $scope.remove = function(chat) {
//    Chats.remove(chat);
//  };
//})
//
//.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
//  $scope.chat = Chats.get($stateParams.chatId);
//    $scope.onTabSelected = function(){
//        alert(1);
//    }
//})
//
//.controller('AccountCtrl', function($scope) {
//    $scope.onTabSelected = function(){
//        alert(1);
//    }
//  $scope.settings = {
//    enableFriends: true
//  };
//});

angular.module('starter.controllers', [])

    .controller('HomeTabCtrl',
        function($scope,$ionicSlideBoxDelegate) {


            $scope.next = function() {
                $ionicSlideBoxDelegate.next();
            };
            $scope.previous = function() {
                $ionicSlideBoxDelegate.previous();
            };
            $scope.slideChanged = function(index) {
                $scope.slideIndex = index;
            };


            console.log('HomeTabCtrl');
        })

    .controller('TabCtrl',
        function($scope) {


            $scope.SayHello = function() {
              alert('hello');
            }
        })


    .controller("buttonCtrl",function($scope, $ionicPopup, $timeout){

        $scope.showPopup = function() {
            $scope.data = {}
            var myPopup = $ionicPopup.show({
                template: '<input type="password" ng-model="data.wifi">',
                title: 'Enter Wi-Fi Password',
                subTitle: 'Please use normal things',
                scope: $scope,
                buttons: [
                    { text: 'Cancel' },
                    {
                        text: '<b>Save</b>',
                        type: 'button-positive',
                        onTap: function(e) {
                            if (!$scope.data.wifi) {
                                //不允许用户关闭，除非他键入wifi密码
                                e.preventDefault();
                            } else {
                                return $scope.data.wifi;
                            }
                        }
                    },
                ]
            });
            myPopup.then(function(res) {
                console.log('Tapped!', res);
            });
            $timeout(function() {
                myPopup.close(); //由于某种原因3秒后关闭弹出
            }, 3000);
        }
        // 一个确认对话框
        $scope.showConfirm = function() {
            var confirmPopup = $ionicPopup.confirm({
                title: 'Consume Ice Cream',
                template: 'Are you sure you want to eat this ice cream?'
            });
            confirmPopup.then(function(res) {
                if(res) {
                    console.log('You are sure');
                } else {
                    console.log('You are not sure');
                }
            });
        };

        // 一个提示对话框
        $scope.showAlert = function() {
            var alertPopup = $ionicPopup.alert({
                title: 'Don\'t eat that!',
                template: 'It might taste good'
            });
            alertPopup.then(function(res) {
                console.log('Thank you for not eating my delicious ice cream cone');
            });
        };
    });
